import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:thingskit/utils/UsbController.dart';

class LightContent extends StatelessWidget {
  final UsbController c = Get.put(UsbController());
  final int index;

  LightContent({super.key, required this.index});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: Row(children: [
            Text(
              '${index + 1}-${c.Lights[index]['addr']}',
              style: TextStyle(fontSize: 16),
            ),
          ],)
        ),
        Expanded(
          child: Row(
            children: [
              Text(
                '${c.Lights[index]['group_id']}F-${c.Lights[index]['second_group_id']}',
                style: TextStyle(fontSize: 16),
              ),
              SizedBox(width: 6),
              getSignalIcon(c.Lights[index]['rssi'].toInt()),
              SizedBox(width: 6),
              Text(
                '${c.Lights[index]['rssi']}dbm',
                style: TextStyle(fontSize: 16),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget getSignalIcon(int value) {
    if (value < -75) {
      return Icon(
        Icons.signal_cellular_alt_1_bar_rounded,
        color: Colors.red,
        size: 20,
      );
    } else if (value < -60) {
      return Icon(
        Icons.signal_cellular_alt_2_bar_rounded,
        color: Colors.orange,
        size: 20,
      );
    } else {
      return Icon(
        Icons.signal_cellular_alt_rounded,
        color: Colors.green,
        size: 20,
      );
    }
  }
}
